﻿//=============================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 作 者：江怀玉
// 日 期：2011-10-11
// 描 述：页面基类，所有的aspx页面继承自基类
//        页面基类提供常用的方法和常用的用户信息
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00   2011/10/11   江怀玉           
//=============================================================


using System;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web;
using ZX.DBModule;
using ZX.SPL;
using ZX.Common;
using ZX.BLL;
using ZX.BLL.Extend;

namespace ZX.Web.UI.Controls
{
    public class EditUIPage : EditPage
    {
        /// <summary>
        /// 数据的操作方法 insert / update / delete
        /// </summary>
        public virtual string DataAction
        {
            get
            {
                string id = this.GetStringFromQueryString("id", "");
                if (id == "")
                {
                    return "insert";
                }
                else
                {
                    return "update";
                }
            }
        }
        /// <summary>
        /// 生成界面的HTML
        /// </summary>
        /// <param name="instance">实例化</param>
        /// <param name="entity">New Entity</param>
        /// <returns></returns>
        public virtual string CreateHtml(BaseEntity instance, BaseEntity entity)
        {
            #region 薪资相关表单数据解密
            if (instance != null)
            {

                if (instance.GetTableName() == "salBaseSalary")
                {
                    ZX.EHR.Library.salBaseSalary salaryInstance = instance as ZX.EHR.Library.salBaseSalary;
                    salaryInstance.BaseSalary = EncryptData.EncryptSalary.Decrypt(salaryInstance.BaseSalary, salaryInstance.ID.ToString());
                    salaryInstance.BaseSalaryHou = EncryptData.EncryptSalary.Decrypt(salaryInstance.BaseSalaryHou, salaryInstance.ID.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salSalaryInterception")
                {
                    ZX.EHR.Library.salSalaryInterception salaryInstance = instance as ZX.EHR.Library.salSalaryInterception;
                    salaryInstance.InterceptionSum = EncryptData.EncryptSalary.Decrypt(salaryInstance.InterceptionSum, salaryInstance.InterceptionId.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salSalaryReissue")
                {
                    ZX.EHR.Library.salSalaryReissue salaryInstance = instance as ZX.EHR.Library.salSalaryReissue;
                    salaryInstance.reissueSum = EncryptData.EncryptSalary.Decrypt(salaryInstance.reissueSum, salaryInstance.reissueId.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salOvertimeFee")
                {
                    ZX.EHR.Library.salOvertimeFee salaryInstance = instance as ZX.EHR.Library.salOvertimeFee;
                    salaryInstance.workDayOvertimeFee = EncryptData.EncryptSalary.Decrypt(salaryInstance.workDayOvertimeFee, salaryInstance.ID.ToString());
                    salaryInstance.weekDayOvertimeFee = EncryptData.EncryptSalary.Decrypt(salaryInstance.weekDayOvertimeFee, salaryInstance.ID.ToString());
                    salaryInstance.holidayOvertimeFee = EncryptData.EncryptSalary.Decrypt(salaryInstance.holidayOvertimeFee, salaryInstance.ID.ToString());
                    salaryInstance.dutyFee = EncryptData.EncryptSalary.Decrypt(salaryInstance.dutyFee, salaryInstance.ID.ToString());
                    salaryInstance.meetingsOvertimeFee = EncryptData.EncryptSalary.Decrypt(salaryInstance.meetingsOvertimeFee, salaryInstance.ID.ToString());
                    salaryInstance.overtimeFeeTotal = EncryptData.EncryptSalary.Decrypt(salaryInstance.overtimeFeeTotal, salaryInstance.ID.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salBasicSubsidy")
                {
                    ZX.EHR.Library.salBasicSubsidy salaryInstance = instance as ZX.EHR.Library.salBasicSubsidy;
                    salaryInstance.houseSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.houseSubsidy, salaryInstance.ID.ToString());
                    salaryInstance.communicationSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.communicationSubsidy, salaryInstance.ID.ToString());
                    salaryInstance.diningSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.diningSubsidy, salaryInstance.ID.ToString());
                    salaryInstance.travelSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.travelSubsidy, salaryInstance.ID.ToString());
                    salaryInstance.otherSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.otherSubsidy, salaryInstance.ID.ToString());
                    salaryInstance.subsidyTotal = EncryptData.EncryptSalary.Decrypt(salaryInstance.subsidyTotal, salaryInstance.ID.ToString());
                    salaryInstance.fixedSubsidy = EncryptData.EncryptSalary.Decrypt(salaryInstance.fixedSubsidy, salaryInstance.ID.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salLargeClassBonus")
                {
                    ZX.EHR.Library.salLargeClassBonus salaryInstance = instance as ZX.EHR.Library.salLargeClassBonus;
                    salaryInstance.largeClassBonus = EncryptData.EncryptSalary.Decrypt(salaryInstance.largeClassBonus, salaryInstance.ID.ToString());
                    instance = salaryInstance;
                }
                if (instance.GetTableName() == "salPerformanceBonus")
                {
                    ZX.EHR.Library.salPerformanceBonus salaryInstance = instance as ZX.EHR.Library.salPerformanceBonus;
                    salaryInstance.projectBonus = EncryptData.EncryptSalary.Decrypt(salaryInstance.projectBonus, salaryInstance.ID.ToString());
                    salaryInstance.quarterBonus = EncryptData.EncryptSalary.Decrypt(salaryInstance.quarterBonus, salaryInstance.ID.ToString());
                    salaryInstance.yearendBonus = EncryptData.EncryptSalary.Decrypt(salaryInstance.yearendBonus, salaryInstance.ID.ToString());
                    salaryInstance.otherBonus = EncryptData.EncryptSalary.Decrypt(salaryInstance.otherBonus, salaryInstance.ID.ToString());
                    salaryInstance.bonusTotal = EncryptData.EncryptSalary.Decrypt(salaryInstance.bonusTotal, salaryInstance.ID.ToString());
                    instance = salaryInstance;
                }
            }
            #endregion
            if (entity == null)
            {
                if (!(instance is DataTableBaseEntity))
                {
                    return ("var instance=[" + instance.ToJSON().Replace("\\\\\"", "\\\"").Replace("\\", "\\\\") + "];");
                }
                else
                {
                    return ("var instance=[" + (instance as DataTableBaseEntity).EntityJson.Replace("\\\\\"", "\\\"").Replace("\\", "\\\\") + "];");
                }

            }
            else
            {
                if (!(entity is DataTableBaseEntity))
                {
                    return ("var instance=[" + entity.ToJSON().Replace("\\\\\"", "\\\"") + "];");
                }
                else
                {
                    return ("var instance=[" + (entity as DataTableBaseEntity).EntityJson.Replace("\\\\\"", "\\\"") + "];");
                }
                //return ("var instance=[" + entity.ToJSON().Replace("\n", "[BR]").Replace("\r", "") + "];");
            }
        }

        public virtual string CreateDefaultPropertyValues()
        {
            return ("var userPropertyValues=[" + EmpPropertyValues.ToJSON() + "];");
        }
        public virtual string CreateEditForm(BaseEntity e, IList<EditUIConfig> list)
        {
            string sth = "<tr {3}><td  class='label'><label id=\"lab{0}\" name=\"{4}\">{1}</label></td><td>{2}</td></tr>";
            string strTControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"{1}\" style=\"width:{2}px\" requireType=\"{3}\" class=\"yui-text\" />";
            string strDControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"{1}\" style=\"width:{2}px\" class=\"yui-date\"/>";
            //string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:200px\" class=\"yui-dic\"/>{1}</select>";
            string strEControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"{1}\"  class=\"yui-mail\"/>";
            string strUControl = "<div><input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"{1}\" class=\"yui-upload\" style=\"width:{2}px\"/></div>";
            string strRControl = "<textarea id=\"{0}\" name=\"{0}\"  class=\"yui-area\" style=\"width:{2}px\"/>{1}</textarea>";
            string strCControl = "<input type=\"checkbox\" id=\"{0}\" name=\"{0}\" class=\"yui-check\" >";
            string strNControl = "<input type=\"text\" id=\"{0}\" name=\"{0}\" value=\"{1}\" class=\"yui-number\" style=\"{2}px\"/>";
            string strPControl = "<input type=\"password\" id=\"{0}\" name=\"{0}\" value=\"{1}\" class=\"yui-number\" style=\"{2}px\"/>";
            string strOControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\"/><input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"/>";
            string strZControl = "<input type=\"hidden\"  id=\"{0}\" name=\"{0}\" value=\"{1}\"/><input type=\"text\" id=\"txt{0}\" value=\"{2}\" readonly=\"readonly\" name=\"{2}\" style=\"width:{3}px\" class=\"yui-dept\"/><button id=\"btn{0}\" name=\"{4}\" type=\"button\">选择</button>";
            string strBControl = "<button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择课程</button>";
            //string strCBControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\"/><input type=\"hidden\" id=\"{0}\" readonly=\"readonly\" name=\"{0}\" class=\"yui-dept\"/><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\" value=\"\"  class=\"yui-text\" dtype=\"{1}\"/><input id=\"btn{0}\" type=\"button\"  value=\"选择\">";
            StringBuilder strHtml = new StringBuilder("<Table>");

            if (list != null)
            {
                if (list.Count > 0)
                {
                    foreach (var entity in list)
                    {
                        EditUIConfig o = entity as EditUIConfig;
                        string c;

                        object ov;
                        if (e is DataTableBaseEntity)
                        {
                            ov = ((DataTableBaseEntity)e).DRow[o.FieldName];
                        }
                        else
                        {
                            ov = ZX.Common.Globals.GetPropertyValue(e, o.FieldName);
                        }
                        switch (o.ControlType.Trim().ToUpper())
                        {
                            case "T"://文本
                                c = string.Format(strTControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length, o.IsRequire);
                                break;
                            case "D"://日期
                                c = string.Format(strDControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "S"://下拉
                                c = CreateSelect(o, entity, o.Length);
                                break;
                            case "U"://上传
                                c = string.Format(strUControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "E"://邮件
                                c = string.Format(strEControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "R"://富文本
                                c = string.Format(strRControl, o.FieldName, ov == null ? "" : ov.ToString().Replace("[BR]", "\n").Replace("[B]", "'"), o.Length);
                                break;
                            case "C"://Check Box
                                c = string.Format(strCControl, o.FieldName, ov == null ? "" : ov.ToString());
                                break;
                            case "P"://Password
                                c = string.Format(strPControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "N"://Number
                                c = string.Format(strNControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "O"://Number
                                c = string.Format(strOControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "B"://选择课程
                                c = string.Format(strBControl, o.FieldName, ov == null ? "" : ov.ToString(), GetName(ov == null ? "" : ov.ToString(), o.ZType), o.Length, o.ZType);
                                break;
                            case "Z"://组合选择框
                                c = string.Format(strZControl, o.FieldName, ov == null ? "" : ov.ToString(), GetName(ov == null ? "" : ov.ToString(), o.ZType), o.Length, o.ZType);
                                break;
                            default:
                                c = string.Format(strTControl, o.FieldName, ov == null ? "" : ov.ToString());
                                break;
                        }
                        strHtml.Append(string.Format(sth, o.EditConfigID, o.Caption, c, o.IsVisiable == "Y" ? "" : "style='display:none'", o.FieldName));
                    }
                }
            }
            strHtml.Append("</table>");
            return strHtml.ToString();
            //BaseEntity entity = bInstance.GetEntityById(id) as BaseEntity;
        }

        public virtual string CreateScript(IList<EditUIConfig> list)
        {
            string strScript = "instance[0].{0}=$('#{0}').val().replace(/\\+/g,'[J]');\n";
            StringBuilder strHtml = new StringBuilder("");
            if (list != null)
            {
                foreach (var o in list)
                {
                    //EditUICofig o = entity as EditUICofig;
                    strHtml.Append(string.Format(strScript, o.FieldName));
                }
            }
            return strHtml.ToString();
        }
        //textarea id="TextArea1" cols="20" name="S1" rows="2"></textarea>

        public string CreateEditReForm(IList<EditUIConfig> list)
        {
            // <label for="phone">Phone</label>
            //<input id="phone" name="phone" value="905 555 1212" type="text"/><br/>

            //<!-- This is a 2 column text box (label + field) -->
            //<label for="address" rel="100pct">Address</label>
            string sth = "<label id=\"lab{0}\" for=\"{0}\" {3}>{1}</label>{2}<br />";
            string strTControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"   class=\"yui-text\" dtype=\"{1}\"  style=\"width:{2}px\"/>";
            string strDControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"  class=\"yui-date\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strEControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"  class=\"yui-mail\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strUControl = "<div><input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\" class=\"yui-upload\" dtype=\"{1}\" style=\"width:{2}px\"/></div>";
            string strRControl = "<textarea id=\"{0}\" name=\"{0}\"  class=\"yui-area\" dtype=\"{1}\"  style=\"width:{2}px\"/></textarea>";
            string strNControl = "<input id=\"{0}\" name=\"{0}\"  class=\"yui-number\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strCControl = "<input type=\"checkbox\" id=\"{0}\" name=\"{0}\" class=\"yui-check\" dtype=\"{1}\" >";
            string strPControl = "<input type=\"password\" id=\"{0}\" name=\"{0}\" class=\"yui-password\" dtype=\"{1}\"  style=\"width:{2}px\">";
            string strOControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"  readonly=\"true\"/>";
            string strZControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"/><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\"  readonly=\"true\" value=\"\"  class=\"yui-text\" dtype=\"{1}\"  style=\"width:{2}px\"/><button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择</button>";
            //string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:200px\" class=\"yui-dic\"/>{1}</select>";
            StringBuilder strHtml = new StringBuilder("<Table>");
            if (list != null)
            {
                if (list.Count > 0)
                {
                    foreach (var o in list)
                    {
                        //EditUICofig o = entity as EditUICofig;
                        string c = o.ColSpan >= 2 ? "rel=\"100pct\"" : "";
                        switch (o.ControlType)
                        {
                            case "T"://普通TextBox
                                c = string.Format(strTControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "D"://日期TextBox
                                c = string.Format(strDControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "S"://下拉
                                c = CreateSelect(o, o.Length);
                                break;
                            case "U"://上传
                                c = string.Format(strUControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "E"://邮件
                                c = string.Format(strEControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "R"://富文本
                                c = string.Format(strRControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "C"://Check Box
                                c = string.Format(strCControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "N"://数值
                                c = string.Format(strNControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "P"://密码
                                c = string.Format(strPControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "O":
                                c = string.Format(strOControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "Z"://组合选择框
                                c = string.Format(strZControl, o.FieldName, o.ControlType, o.ZType, o.Length);
                                break;
                            default://默认
                                c = string.Format(strTControl, o.FieldName, o.ControlType, o.Length);
                                break;
                        }
                        strHtml.Append(string.Format(sth, o.EditConfigID, o.Caption, c, o.IsVisiable == "Y" ? "" : "style='display:none'"));
                    }
                }
            }
            strHtml.Append("</table>");
            return strHtml.ToString();
        }

        public string CreateEditForm(IList<EditUIConfig> list)
        {
            string sth = "<tr {3}><td class='label' ><label id=\"lab{0}\" name=\"{4}\">{1}</label></td><td id=\"td{4}\">{2}</td></tr>";
            string strTControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"   class=\"yui-text\" dtype=\"{1}\"  style=\"width:{2}px\" requireType=\"{3}\" />";
            string strDControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"  class=\"yui-date\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strEControl = "<input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\"  class=\"yui-mail\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strUControl = "<div><input id=\"{0}\" name=\"{0}\" type=\"text\" value=\"\" class=\"yui-upload\" dtype=\"{1}\" style=\"width:{2}px\"/></div>";
            string strRControl = "<textarea id=\"{0}\" name=\"{0}\"  class=\"yui-area\" dtype=\"{1}\"  style=\"width:{2}px\"/></textarea>";
            string strNControl = "<input id=\"{0}\" name=\"{0}\"  class=\"yui-number\" dtype=\"{1}\"   style=\"width:{2}px\"/>";
            string strCControl = "<input type=\"checkbox\" id=\"{0}\" name=\"{0}\" class=\"yui-check\" dtype=\"{1}\" >";
            string strPControl = "<input type=\"password\" id=\"{0}\" name=\"{0}\" class=\"yui-password\" dtype=\"{1}\"  style=\"width:{2}px\">";
            string strOControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"  readonly=\"true\"/>";
            string strZControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"/><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\"  readonly=\"readonly\" value=\"\"  class=\"yui-text\" dtype=\"{1}\"  style=\"width:{3}px\"/><button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择</button>";
            string strBControl = "<button id=\"btn{0}\" name=\"{2}\" type=\"button\" value=\"\">选择课程</button>";
            //string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:200px\" class=\"yui-dic\"/>{1}</select>";
            StringBuilder strHtml = new StringBuilder("<Table>");
            if (list != null)
            {
                if (list.Count > 0)
                {
                    foreach (var o in list)
                    {
                        //EditUICofig o = entity as EditUICofig;
                        string c;
                        switch (o.ControlType)
                        {
                            case "T"://普通TextBox
                                c = string.Format(strTControl, o.FieldName, o.ControlType, o.Length, o.IsRequire);
                                break;
                            case "D"://日期TextBox
                                c = string.Format(strDControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "S"://下拉
                                c = CreateSelect(o, o.Length);
                                break;
                            case "U"://上传
                                c = string.Format(strUControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "E"://邮件
                                c = string.Format(strEControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "R"://富文本
                                c = string.Format(strRControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "C"://Check Box
                                c = string.Format(strCControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "N"://数值
                                c = string.Format(strNControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "P"://密码
                                c = string.Format(strPControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "O":
                                c = string.Format(strOControl, o.FieldName, o.ControlType, o.Length);
                                break;
                            case "Z"://组合选择框
                                c = string.Format(strZControl, o.FieldName, o.ControlType, o.ZType, o.Length);
                                break;
                            case "B"://选择课程
                                c = string.Format(strBControl, o.FieldName, o.ControlType, o.ZType, o.Length);
                                break;
                            default://默认
                                c = string.Format(strTControl, o.FieldName, o.ControlType, o.Length);
                                break;
                        }
                        strHtml.Append(string.Format(sth, o.EditConfigID, o.Caption, c, o.IsVisiable == "Y" ? "" : "style='display:none'", o.FieldName));
                    }
                }
            }
            strHtml.Append("</table>");
            return strHtml.ToString();
        }
         
        public string CreateViewForm(BaseEntity e, IList<EditUIConfig> list)
        {
            string sth = "<tr {3}><td  class='label'><label id=\"lab{0}\" name=\"{4}\">{1}:</label></td><td>{2}</td></tr>";
            string strTControl = " <label id=\"{0}\"  name=\"{0}\" style=\"width:{2}px;color:Blue\"  >{1}</label>";
            string strDControl = "<label id=\"{0}\"  name=\"{0}\"   style=\"width:{2}px;color:Blue\" >{1}</label>";
            //string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:200px\" class=\"yui-dic\"/>{1}</select>";
            string strEControl = "<label id=\"{0}\"  name=\"{0}\" style=\"width:{2}px;color:Blue\" >{1}</label>";
            string strUControl = "<div><label id=\"{0}\"  name=\"{0}\" style=\"width:{2}px;color:Blue\" >{1}</label></div>";
            string strRControl = "<textarea id=\"{0}\" name=\"{0}\"  class=\"yui-area\" style=\"width:{2}px\"/>{1}</textarea>";
            string strCControl = "<input type=\"checkbox\" id=\"{0}\" name=\"{0}\" class=\"yui-check\" >";
            string strNControl = "<label id=\"{0}\"  name=\"{0}\" style=\"width:{2}px;color:Blue\" >{1}</label>";
            string strPControl = "<input type=\"password\" id=\"{0}\" name=\"{0}\" value=\"{1}\" class=\"yui-number\" style=\"{2}px\"/>";
            string strOControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\"/><input type=\"hidden\" id=\"{0}\" name=\"{0}\" class=\"yui-dept\"/>";
            string strZControl = "<input type=\"hidden\"  id=\"{0}\" name=\"{0}\" value=\"{1}\"/><label id=\"{0}\"  name=\"{0}\" style=\"width:{3}px;color:Blue\" >{2}</label>";

            //string strCBControl = "<input type=\"hidden\" id=\"{0}\" name=\"{0}\"/><input type=\"hidden\" id=\"{0}\" readonly=\"readonly\" name=\"{0}\" class=\"yui-dept\"/><input id=\"txt{0}\" name=\"txt{0}\" type=\"text\" value=\"\"  class=\"yui-text\" dtype=\"{1}\"/><input id=\"btn{0}\" type=\"button\"  value=\"选择\">";
            StringBuilder strHtml = new StringBuilder("<Table>");

            if (list != null)
            {
                if (list.Count > 0)
                {
                    foreach (var entity in list)
                    {
                        EditUIConfig o = entity as EditUIConfig;
                        string c;
                        object ov;
                        if (e is DataTableBaseEntity)
                        {
                            ov = ((DataTableBaseEntity)e).DRow[o.FieldName];
                        }
                        else
                        {
                            ov = ZX.Common.Globals.GetPropertyValue(e, o.FieldName);
                        }
                        switch (o.ControlType.Trim().ToUpper())
                        {
                            case "T"://文本
                                c = string.Format(strTControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "D"://日期
                                c = string.Format(strDControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "S"://下拉
                                c = CreateSelect(o, entity, o.Length);
                                break;
                            case "U"://上传
                                c = string.Format(strUControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "E"://邮件
                                c = string.Format(strEControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "R"://富文本
                                c = string.Format(strRControl, o.FieldName, ov == null ? "" : ov.ToString().Replace("[BR]", "\n").Replace("[B]", "'"), o.Length);
                                break;
                            case "C"://Check Box
                                c = string.Format(strCControl, o.FieldName, ov == null ? "" : ov.ToString());
                                break;
                            case "P"://Password
                                c = string.Format(strPControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "N"://Number
                                c = string.Format(strNControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "O"://Number
                                c = string.Format(strOControl, o.FieldName, ov == null ? "" : ov.ToString(), o.Length);
                                break;
                            case "Z"://组合选择框
                                c = string.Format(strZControl, o.FieldName, ov == null ? "" : ov.ToString(), GetName(ov == null ? "" : ov.ToString(), o.ZType), o.Length);
                                break;
                            default:
                                c = string.Format(strTControl, o.FieldName, ov == null ? "" : ov.ToString());
                                break;
                        }
                        strHtml.Append(string.Format(sth, o.EditConfigID, o.Caption, c, o.IsVisiable == "Y" ? "" : "style='display:none'", o.FieldName));
                    }
                }
            }
            strHtml.Append("</table>");
            return strHtml.ToString();
        }
        public string CreateSelect(EditUIConfig e, int width)
        {
            StringBuilder strHtml = new StringBuilder("");
            string strSOption = "<option value=\"{0}\">{1}</option>\n";
            string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:{2}px\" class=\"yui-dic\"/>{1}</select>";
            IList<Dictionary> list = null;
            if (e.DataSourceType.ToLower() == "json")
            {
                list = Globals.JSonToObject<IList<Dictionary>>(e.DataSource);
            }
            if (e.DataSourceType.ToLower() == "sql")
            {
                BaseBussnies instance = new BaseBussnies();
                list = instance.GetEntitysBySqlComm<Dictionary>(e.DataSource.Replace("[B]", "'"));
            }
            if (e.DataSourceType.ToLower() == "dic")
            {
                BaseBussnies instance = new BaseBussnies();
                list = instance.GetEntitysBySqlComm<Dictionary>(string.Format("Exec [dbo].[sp_GetDicList] '{0}'", e.DataSource));
            }
            if (list != null)
            {
                strHtml.Append(string.Format(strSOption, "", ""));
                foreach (var d in list)
                {
                    strHtml.Append(string.Format(strSOption, d.ValueMember, d.DisplayMember));
                }
            }
            return string.Format(strSControl, e.FieldName, strHtml.ToString(), width);
        }

        public virtual string CreateSelect(EditUIConfig e, BaseEntity entity, int width)
        {
            StringBuilder strHtml = new StringBuilder("");
            string strSOption = "<option value=\"{0}\" >{1}</option>\n";
            string strSControl = "<select  id=\"{0}\" name=\"{0}\"  style=\"width:{2}px\" class=\"yui-dic\"/>{1}</select>";
            object ov = ZX.Common.Globals.GetPropertyValue(entity, e.FieldName);
            IList<Dictionary> list = null;
            if (e.DataSourceType.ToLower() == "json")
            {
                list = Globals.JSonToObject<IList<Dictionary>>(e.DataSource);
            }
            if (e.DataSourceType.ToLower() == "sql")
            {
                BaseBussnies instance = new BaseBussnies();
                list = instance.GetEntitysBySqlComm<Dictionary>(e.DataSource.Replace("[B]", "'"));
            }
            if (e.DataSourceType.ToLower() == "dic")
            {
                BaseBussnies instance = new BaseBussnies();
                list = instance.GetEntitysBySqlComm<Dictionary>(string.Format("Exec [dbo].[sp_GetDicList] '{0}'", e.DataSource));
            }
            if (list != null)
            {
                strHtml.Append(string.Format(strSOption, "", ""));
                foreach (var d in list)
                {
                    strHtml.Append(string.Format(strSOption, d.ValueMember, d.DisplayMember, ((ov == null ? "" : ov.ToString()) == d.ValueMember) ? "selected" : ""));
                }
            }
            return string.Format(strSControl, e.FieldName, strHtml.ToString(), width);
        }

        public virtual string InitControl(IList<EditUIConfig> list)
        {
            //;
            //$('.yui-upload').upload();
            StringBuilder strHTML = new StringBuilder("");
            foreach (var o in list)
            {
                switch (o.ControlType)
                {
                    case "D":
                        strHTML.Append("$('#" + o.FieldName + "').cld();\n");
                        break;
                    case "U":
                        strHTML.Append("$('#" + o.FieldName + "').upload();\n");
                        break;
                    case "Z":
                        strHTML.Append("$('#" + o.FieldName + "').select();\n");
                        break;
                    default:
                        break;

                }
            }
            return strHTML.ToString();
        }

        /// <summary>引用的程序集没有强名称
        /// 
        /// </summary>
        /// <returns></returns>
        public virtual string SetMasterID()
        {
            string MasterID = GetStringFromQueryString("masterid", "");
            if (!string.IsNullOrEmpty(MasterID))
            {
                return "instance[0]." + MasterID + "=Parent.ParentID";
            }
            return "";
        }

        public virtual string GetName(string key, string type)
        {
            string strEntity = this.GetStringFromQueryString("entity", "E_Menu");
            string condition = "TableName='{0}' AND [key] in ({1})";
            string[] keys = key.TrimEnd(',').Split(',');
            StringBuilder sb = new StringBuilder();
            foreach (string id in keys)
            {
                sb.Append("\'" + id + "\'");
                sb.Append(",");

            }
            switch (type.ToLower())
            {
                case "u":
                    condition = string.Format(condition, "DatUser", sb.ToString().TrimEnd(','));
                    break;
                case "t":
                    condition = string.Format(condition, "DatUser", sb.ToString().TrimEnd(','));
                    break;
                case "c":
                    condition = string.Format(condition, "V_TrCustomer", sb.ToString().TrimEnd(','));
                    break;
                case "e":
                    condition = string.Format(condition, "DatEmployee", sb.ToString().TrimEnd(','));
                    break;
                case "d":
                    condition = string.Format(condition, "DatDepartment", sb.ToString().TrimEnd(','));
                    break;
                case "a":
                    condition = string.Format(condition, "V_TrActivityCourseExpectation", sb.ToString().TrimEnd(','));
                    break;
                case "b":
                    condition = string.Format(condition, "TrCourse", sb.ToString().TrimEnd(','));
                    break;
                case "w":
                    condition = string.Format(condition, "DatDepartment", sb.ToString().TrimEnd(','));
                    break;
                case "p":
                    condition = string.Format(condition, "DatPost", sb.ToString().TrimEnd(','));
                    break;
                case "m":
                    condition = string.Format(condition, "V_CrmCustomer", sb.ToString().TrimEnd(','));
                    break;
                case "v":
                    condition = string.Format(condition, "V_UserEmp", sb.ToString().TrimEnd(','));
                    break;
                case "s"://主职部门
                    condition = string.Format(condition, "DatDepartment", sb.ToString().TrimEnd(','));
                    break;
                default:
                    condition = string.Format(condition, "DatUser", sb.ToString().TrimEnd(','));
                    break;
            }
            IList<V_SetTableList> list = new EnttityBLL().GetEntitys<V_SetTableList>(condition);
            StringBuilder sbNames = new StringBuilder();
            if (list != null && list.Count > 0)
            {
                foreach (V_SetTableList v_s in list)
                {
                    sbNames.Append(v_s.Caption);
                    sbNames.Append(",");
                }
            }
            return sbNames.ToString().TrimEnd(',');

        }
    }
}
